package com.iplant.wms.serviceImpl;

import com.iplant.base.po.OutResult;
import com.iplant.base.po.Pagination;
import com.iplant.base.po.ServiceResult;
import com.iplant.base.po.enums.ExceptionTypes;
import com.iplant.basic.service.po.bms.BMSEmployee;
import com.iplant.wms.service.BRMService;
import com.iplant.wms.service.po.brm.*;
import com.iplant.wms.serviceImpl.dao.brm.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BRMServiceImpl implements BRMService {

    public BRMServiceImpl() {
        // TODO Auto-generated constructor stub
    }

    private static final Logger logger = LoggerFactory.getLogger(BRMServiceImpl.class);

    private static BRMService Instance = null;

    public static BRMService getInstance() {
        if (Instance == null) {
            Instance = new BRMServiceImpl();
        }

        return Instance;
    }


    //补货模板
    @Override
    public ServiceResult<Integer> BRM_UpdateReplenishRule(BMSEmployee wLoginUser, BRMReplenishRule wReplenishRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMReplenishRuleDAO.getInstance().UpdatePo(wLoginUser, wReplenishRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_DeleteReplenishRule(BMSEmployee wLoginUser, BRMReplenishRule wReplenishRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMReplenishRuleDAO.getInstance().DeletePO(wLoginUser, wReplenishRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_ActiveReplenishRule(BMSEmployee wLoginUser, BRMReplenishRule wReplenishRule, int wActive) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMReplenishRuleDAO.getInstance().ActivePO(wLoginUser, wReplenishRule, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<BRMReplenishRule> BRM_QueryReplenishRule(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<BRMReplenishRule> wResult = new ServiceResult<BRMReplenishRule>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMReplenishRuleDAO.getInstance().SelectPO(wLoginUser, wID,
                    wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMReplenishRule>> BRM_QueryReplenishRuleList(
            BMSEmployee wLoginUser, String wName, int wStoreID, int wShelvesRuleID, int wActive,
            Pagination wPagination) {
        ServiceResult<List<BRMReplenishRule>> wResult = new ServiceResult<List<BRMReplenishRule>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMReplenishRuleDAO.getInstance().BRM_QueryReplenishRuleList(wLoginUser,
                    wName, wStoreID, wShelvesRuleID, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    //上架模板
    @Override
    public ServiceResult<Integer> BRM_UpdateShelvesRule(BMSEmployee wLoginUser, BRMShelvesRule wShelvesRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMShelvesRuleDAO.getInstance().UpdatePo(wLoginUser, wShelvesRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_DeleteShelvesRule(BMSEmployee wLoginUser, BRMShelvesRule wShelvesRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMShelvesRuleDAO.getInstance().BRM_DeleteShelvesRule(wLoginUser, wShelvesRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_ActiveShelvesRule(BMSEmployee wLoginUser, BRMShelvesRule wShelvesRule, int wActive) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMShelvesRuleDAO.getInstance().ActivePO(wLoginUser, wShelvesRule, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<BRMShelvesRule> BRM_QueryShelvesRule(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<BRMShelvesRule> wResult = new ServiceResult<BRMShelvesRule>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMShelvesRuleDAO.getInstance().SelectPO(wLoginUser, wID,
                    wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMShelvesRule>> BRM_QueryShelvesRuleList(
            BMSEmployee wLoginUser, String wName, int wStoreID, int wActive,
            Pagination wPagination) {
        ServiceResult<List<BRMShelvesRule>> wResult = new ServiceResult<List<BRMShelvesRule>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMShelvesRuleDAO.getInstance().BRM_QueryShelvesRuleList(wLoginUser, wName, wStoreID, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    //上架属性
    @Override
    public ServiceResult<Integer> BRM_UpdateShelvesProp(BMSEmployee wLoginUser, BRMShelvesProp wShelvesProp) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMShelvesPropDAO.getInstance().UpdatePo(wLoginUser, wShelvesProp, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> BRM_ActiveShelvesProp(BMSEmployee wLoginUser, BRMShelvesProp wShelvesProp, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMShelvesPropDAO.getInstance().ActivePO(wLoginUser, wShelvesProp, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMShelvesProp>> BRM_QueryShelvesPropList(BMSEmployee wLoginUser, int wRuleID, String wName, String wCode,
                                                                        int wActive, Pagination wPagination) {
        ServiceResult<List<BRMShelvesProp>> wResult = new ServiceResult<List<BRMShelvesProp>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMShelvesPropDAO.getInstance().BRM_QueryShelvesPropList(wLoginUser, wRuleID, wName, wCode,
                    wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }
    //上架范围

    @Override
    public ServiceResult<Integer> BRM_UpdateShelvesRange(BMSEmployee wLoginUser, BRMShelvesRange wShelvesRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            BRMShelvesRangeDAO.getInstance().UpdatePo(wLoginUser, wShelvesRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_DeleteShelvesRange(BMSEmployee wLoginUser, BRMShelvesRange wShelvesRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            BRMShelvesRangeDAO.getInstance().DeletePO(wLoginUser, wShelvesRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<List<BRMShelvesRange>> BRM_QueryShelvesRangeList(
            BMSEmployee wLoginUser, int wStoreID, List<Integer> wCustomerIDList, int wMaterialGroupID, String wMaterialGroupFullName,
            int wMaterialID, String wMaterialCode, String wMaterialLike, Pagination wPagination) {
        ServiceResult<List<BRMShelvesRange>> wResult = new ServiceResult<List<BRMShelvesRange>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMShelvesRangeDAO.getInstance().BRM_QueryShelvesRangeList(wLoginUser,
                    wStoreID, wCustomerIDList, wMaterialGroupID, wMaterialGroupFullName, wMaterialID, wMaterialCode, wMaterialLike, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    //抽样管理


    //抽样模板
    @Override
    public ServiceResult<Integer> BRM_UpdateSampleRule(BMSEmployee wLoginUser, BRMSampleRule wSampleRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);

            BRMSampleRuleDAO.getInstance().UpdatePo(wLoginUser, wSampleRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_DeleteSampleRule(BMSEmployee wLoginUser, BRMSampleRule wSampleRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMSampleRuleDAO.getInstance().BRM_DeleteSampleRule(wLoginUser, wSampleRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_ActiveSampleRule(BMSEmployee wLoginUser, BRMSampleRule wSampleRule, int wActive) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMSampleRuleDAO.getInstance().ActivePO(wLoginUser, wSampleRule, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<BRMSampleRule> BRM_QuerySampleRule(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<BRMSampleRule> wResult = new ServiceResult<BRMSampleRule>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMSampleRuleDAO.getInstance().SelectPO(wLoginUser, wID,
                    wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMSampleRule>> BRM_QuerySampleRuleList(
            BMSEmployee wLoginUser, String wName, int wActive,
            Pagination wPagination) {
        ServiceResult<List<BRMSampleRule>> wResult = new ServiceResult<List<BRMSampleRule>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMSampleRuleDAO.getInstance().BRM_QuerySampleRuleList(wLoginUser, wName, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    //抽样属性
    @Override
    public ServiceResult<Integer> BRM_UpdateSampleProp(BMSEmployee wLoginUser, BRMSampleProp wSampleProp) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMSamplePropDAO.getInstance().UpdatePo(wLoginUser, wSampleProp, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> BRM_ActiveSampleProp(BMSEmployee wLoginUser, BRMSampleProp wSampleProp, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMSamplePropDAO.getInstance().ActivePO(wLoginUser, wSampleProp, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMSampleProp>> BRM_QuerySamplePropList(
            BMSEmployee wLoginUser, int wRuleID, String wName, String wCode, int wASNTypeID, int wActive,
            Pagination wPagination) {
        ServiceResult<List<BRMSampleProp>> wResult = new ServiceResult<List<BRMSampleProp>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMSamplePropDAO.getInstance().BRM_QuerySamplePropList(wLoginUser, wRuleID, wName, wCode, wASNTypeID,
                    wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<BRMSampleProp> BRM_QuerySampleProp(
            BMSEmployee wLoginUser, String wMaterialNo, int wASNTypeID, double wMaterialNum) {
        ServiceResult<BRMSampleProp> wResult = new ServiceResult<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMSamplePropDAO.getInstance().BRM_QuerySampleProp(wLoginUser, wMaterialNo, wASNTypeID, wMaterialNum, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    //抽样范围

    @Override
    public ServiceResult<Integer> BRM_UpdateSampleRange(BMSEmployee wLoginUser, BRMSampleRange wSampleRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            BRMSampleRangeDAO.getInstance().UpdatePo(wLoginUser, wSampleRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_DeleteSampleRange(BMSEmployee wLoginUser, BRMSampleRange wSampleRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            BRMSampleRangeDAO.getInstance().DeletePO(wLoginUser, wSampleRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMSampleRange>> BRM_QuerySampleRangeList(
            BMSEmployee wLoginUser, int wMaterialGroupID, String wMaterialGroupFullName,
            int wMaterialID, String wMaterialCode, String wMaterialLike, Pagination wPagination) {
        ServiceResult<List<BRMSampleRange>> wResult = new ServiceResult<List<BRMSampleRange>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMSampleRangeDAO.getInstance().BRM_QuerySampleRangeList(
                    wLoginUser, wMaterialGroupID, wMaterialGroupFullName, wMaterialID, wMaterialCode, wMaterialLike, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    //序列号规则模板
    @Override
    public ServiceResult<Integer> BRM_UpdateSerialNoRule(BMSEmployee wLoginUser, BRMSerialNoRule wSerialNoRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMSerialNoRuleDAO.getInstance().UpdatePo(wLoginUser, wSerialNoRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_DeleteSerialNoRule(BMSEmployee wLoginUser, BRMSerialNoRule wSerialNoRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMSerialNoRuleDAO.getInstance().BRM_DeleteSerialNoRule(wLoginUser, wSerialNoRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_ActiveSerialNoRule(BMSEmployee wLoginUser, BRMSerialNoRule wSerialNoRule, int wActive) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMSerialNoRuleDAO.getInstance().ActivePO(wLoginUser, wSerialNoRule, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<BRMSerialNoRule> BRM_QuerySerialNoRule(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<BRMSerialNoRule> wResult = new ServiceResult<BRMSerialNoRule>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMSerialNoRuleDAO.getInstance().SelectPO(wLoginUser, wID,
                    wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMSerialNoRule>> BRM_QuerySerialNoRuleList(
            BMSEmployee wLoginUser, String wName, int wActive,
            Pagination wPagination) {
        ServiceResult<List<BRMSerialNoRule>> wResult = new ServiceResult<List<BRMSerialNoRule>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMSerialNoRuleDAO.getInstance().BRM_QuerySerialNoRuleList(
                    wLoginUser, wName, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    //序列号规则范围

    @Override
    public ServiceResult<Integer> BRM_UpdateSerialNoRange(BMSEmployee wLoginUser, BRMSerialNoRange wSerialNoRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            BRMSerialNoRangeDAO.getInstance().UpdatePo(wLoginUser, wSerialNoRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_DeleteSerialNoRange(BMSEmployee wLoginUser, BRMSerialNoRange wSerialNoRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            BRMSerialNoRangeDAO.getInstance().DeletePO(wLoginUser, wSerialNoRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMSerialNoRange>> BRM_QuerySerialNoRangeList(
            BMSEmployee wLoginUser, List<Integer> wCustomerIDList, int wMaterialGroupID, String wMaterialGroupFullName,
            int wMaterialID, String wMaterialCode, String wMaterialLike,
            Pagination wPagination) {
        ServiceResult<List<BRMSerialNoRange>> wResult = new ServiceResult<List<BRMSerialNoRange>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMSerialNoRangeDAO.getInstance().BRM_QuerySerialNoRangeList(
                    wLoginUser,  wCustomerIDList, wMaterialGroupID, wMaterialGroupFullName, wMaterialID, wMaterialCode, wMaterialLike, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    //预分配管理


    //预分配模板
    @Override
    public ServiceResult<Integer> BRM_UpdateDistributionRule(
            BMSEmployee wLoginUser, BRMDistributionRule wDistributionRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMDistributionRuleDAO.getInstance().UpdatePo(wLoginUser, wDistributionRule, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_DeleteDistributionRule(
            BMSEmployee wLoginUser, BRMDistributionRule wDistributionRule) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMDistributionRuleDAO.getInstance().BRM_DeleteDistributionRule(wLoginUser, wDistributionRule, wErrorCode);

            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_ActiveDistributionRule(
            BMSEmployee wLoginUser, BRMDistributionRule wDistributionRule, int wActive) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMDistributionRuleDAO.getInstance().ActivePO(wLoginUser, wDistributionRule, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<BRMDistributionRule> BRM_QueryDistributionRule(BMSEmployee wLoginUser, int wID, String wCode) {
        ServiceResult<BRMDistributionRule> wResult = new ServiceResult<BRMDistributionRule>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMDistributionRuleDAO.getInstance().SelectPO(wLoginUser, wID,
                    wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMDistributionRule>> BRM_QueryDistributionRuleList(
            BMSEmployee wLoginUser, int wMethod, int wFirstType, String wName, int wActive, Pagination wPagination) {
        ServiceResult<List<BRMDistributionRule>> wResult = new ServiceResult<List<BRMDistributionRule>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMDistributionRuleDAO.getInstance().BRM_QueryDistributionRuleList(wLoginUser, wMethod, wFirstType, wName, wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    //预分配属性
    @Override
    public ServiceResult<Integer> BRM_UpdateDistributionProp(
            BMSEmployee wLoginUser, BRMDistributionProp wDistributionProp) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMDistributionPropDAO.getInstance().UpdatePo(wLoginUser, wDistributionProp, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


    @Override
    public ServiceResult<Integer> BRM_ActiveDistributionProp(
            BMSEmployee wLoginUser, BRMDistributionProp wDistributionProp, int wActive) {
        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            BRMDistributionPropDAO.getInstance().ActivePO(wLoginUser, wDistributionProp, wActive, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMDistributionProp>> BRM_QueryDistributionPropList(
            BMSEmployee wLoginUser, int wRuleID, String wRuleCode, String wName, String wCode, int wActive,
            Pagination wPagination) {
        ServiceResult<List<BRMDistributionProp>> wResult = new ServiceResult<List<BRMDistributionProp>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMDistributionPropDAO.getInstance().BRM_QueryDistributionPropList(wLoginUser, wRuleID, wRuleCode, wName, wCode,
                    wActive, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<BRMDistributionProp> BRM_QueryDistributionProp(
            BMSEmployee wLoginUser, int wRuleID, String wRuleCode, String wCode) {
        ServiceResult<BRMDistributionProp> wResult = new ServiceResult<>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMDistributionPropDAO.getInstance().BRM_QueryDistributionProp(wLoginUser, wRuleID, wRuleCode, wCode, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    //预分配范围

    @Override
    public ServiceResult<Integer> BRM_UpdateDistributionRange(
            BMSEmployee wLoginUser, BRMDistributionRange wDistributionRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            BRMDistributionRangeDAO.getInstance().UpdatePo(wLoginUser, wDistributionRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<Integer> BRM_DeleteDistributionRange(
            BMSEmployee wLoginUser, BRMDistributionRange wDistributionRange) {

        ServiceResult<Integer> wResult = new ServiceResult<Integer>(0);
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);


            BRMDistributionRangeDAO.getInstance().DeletePO(wLoginUser, wDistributionRange, wErrorCode);


            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }

    @Override
    public ServiceResult<List<BRMDistributionRange>> BRM_QueryDistributionRangeList(
            BMSEmployee wLoginUser, int wMaterialGroupID, String wMaterialGroupFullName, int wMaterialID,
            String wMaterialCode, String wMaterialLike, Pagination wPagination) {
        ServiceResult<List<BRMDistributionRange>> wResult = new ServiceResult<List<BRMDistributionRange>>();
        try {
            OutResult<Integer> wErrorCode = new OutResult<Integer>(0);
            wErrorCode.set(0);
            wResult.Result = BRMDistributionRangeDAO.getInstance().BRM_QueryDistributionRangeList(
                    wLoginUser, wMaterialGroupID, wMaterialGroupFullName, wMaterialID, wMaterialCode, wMaterialLike, wPagination, wErrorCode);
            wResult.FaultCode += ExceptionTypes.getEnumType(wErrorCode.get()).getLabel();

        } catch (Exception e) {
            logger.error(e.toString());
        }
        return wResult;
    }


}
